import { stringifyNumber as c } from '../../stringify/stringifyNumber.js';
const o = t => typeof t == 'bigint' || Number.isInteger(t);
function a(t, i, n, { intAsBigInt: r }) {
  const e = t[0];
  if (
    ((e === '-' || e === '+') && (i += 1),
    (t = t.substring(i).replace(/_/g, '')),
    r)
  ) {
    switch (n) {
      case 2:
        t = `0b${t}`;
        break;
      case 8:
        t = `0o${t}`;
        break;
      case 16:
        t = `0x${t}`;
        break;
    }
    const f = BigInt(t);
    return e === '-' ? BigInt(-1) * f : f;
  }
  const s = parseInt(t, n);
  return e === '-' ? -1 * s : s;
}
function g(t, i, n) {
  const { value: r } = t;
  if (o(r)) {
    const e = r.toString(i);
    return r < 0 ? '-' + n + e.substr(1) : n + e;
  }
  return c(t);
}
const y = {
    identify: o,
    default: !0,
    tag: 'tag:yaml.org,2002:int',
    format: 'BIN',
    test: /^[-+]?0b[0-1_]+$/,
    resolve: (t, i, n) => a(t, 2, 2, n),
    stringify: t => g(t, 2, '0b'),
  },
  l = {
    identify: o,
    default: !0,
    tag: 'tag:yaml.org,2002:int',
    format: 'OCT',
    test: /^[-+]?0[0-7_]+$/,
    resolve: (t, i, n) => a(t, 1, 8, n),
    stringify: t => g(t, 8, '0'),
  },
  b = {
    identify: o,
    default: !0,
    tag: 'tag:yaml.org,2002:int',
    test: /^[-+]?[0-9][0-9_]*$/,
    resolve: (t, i, n) => a(t, 0, 10, n),
    stringify: c,
  },
  m = {
    identify: o,
    default: !0,
    tag: 'tag:yaml.org,2002:int',
    format: 'HEX',
    test: /^[-+]?0x[0-9a-fA-F_]+$/,
    resolve: (t, i, n) => a(t, 2, 16, n),
    stringify: t => g(t, 16, '0x'),
  };
export { b as int, y as intBin, m as intHex, l as intOct };
